package org.feng.utils.redis;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author by feng
 * @des redisString
 * @date 2021/4/27 14:03
 */
@Component
public class RedisString extends RedisCommon {
    /**
     * 添加
     *
     * @param key
     * @param value
     */
    public RedisTemplate<Object, Object> set(Object key, Object value) {
        redisTemplate.opsForValue().set(key, value);
        return super.redisTemplate;
    }

    /**
     * 添加
     *
     * @param key
     * @param value
     */
    public RedisTemplate<Object, Object> set(Object key, Object value, Long time) {
        redisTemplate.opsForValue().set(key, value, time, TimeUnit.MILLISECONDS);
        return super.redisTemplate;
    }

    /**
     * 获取
     *
     * @param key
     * @return
     */
    public Object get(Object key) {
        return redisTemplate.opsForValue().get(key);
    }

    /**
     * 自增
     *
     * @param key
     * @param value
     * @return
     */
    public Long increment(Object key, Long value) {
        return redisTemplate.opsForValue().increment(key, value);
    }

    /**
     * 自减
     *
     * @param key
     * @param value
     * @return
     */
    public Long decrement(Object key, Long value) {
        return redisTemplate.opsForValue().decrement(key, value);
    }

    /**
     * 长度
     *
     * @param key
     * @return
     */
    public Long size(Object key) {
        return redisTemplate.opsForValue().size(key);
    }

    /**
     * 追加
     *
     * @param key
     * @param value
     */
    public RedisTemplate<Object, Object> append(Object key, String value) {
        redisTemplate.opsForValue().append(key, value);
        return super.redisTemplate;
    }

}

